home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / CONTAINER / Iterator.h < prev    next >
C/C++ Source or Header  |  1992-06-18  |  2KB  |  85 lines

  1. #ifndef Iterator_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define Iterator_First
  7.  
  8. #include "Types.h"
  9. #include "Storage.h"
  10.  
  11. class Container;
  12. class Object;
  13.  
  14. //---- IteratorBase ------------------------------------------------------------
  15.  
  16. class IteratorBase {
  17. #ifdef __GNUG__
  18.     char *dummy;        // g++ warns about empty classes !!
  19. #endif
  20. protected:
  21.     IteratorBase() { };
  22. public:  
  23.     virtual ~IteratorBase() { };
  24.     
  25.     virtual Object *operator()();
  26.     virtual void Reset();
  27.     
  28.      //---- memory allocation
  29.     void *operator new (size_t sz)
  30.     { return Storage::ChunkAlloc(sz); }
  31.     void operator delete(void *vp)
  32.     { Storage::ChunkFree(vp); }
  33. };
  34.  
  35. //---- Iterator ----------------------------------------------------------------
  36.  
  37. class Iterator : public IteratorBase {
  38. friend Container;
  39. protected:
  40.     Iterator();
  41. public:
  42.     ~Iterator();
  43.     void Reset();
  44.     
  45. protected:
  46.     //---- support for robust Iterators
  47.     bool IsActive() { return (started && ! terminated); };
  48.     bool Start();                       // for non-derived classes private
  49.     void Terminate();                   // for non-derived classes private
  50.     virtual Container *GetContainer();
  51.     
  52.     //---- support for robust iterators - events signaled from container
  53.     virtual void AboutToDie(void *ignored= 0);                     
  54.     virtual void AboutToAdd(void *position);  
  55.     virtual void AboutToRemove(void *position);         
  56.     virtual void AboutToEmpty(void *ignored= 0);                                
  57.     virtual void SavePosition(void *ignored= 0);                            
  58.     virtual void ResetPosition(void *ignored= 0);                                
  59. protected:
  60.     bool Started() { return started; };
  61.     bool Terminated() { return terminated; };
  62.     
  63.     static void (Iterator::*aboutToEmpty)(void *);  // ??
  64. private:
  65.     //---- only used by Container
  66.     void ChainIn(Iterator *anchor);
  67.     void ChainOut();
  68.     void Init() { next= this; prev= this; };
  69. private:
  70.     bool started, terminated;          
  71.     Iterator *next, *prev;  // linking iterators - only used by Container
  72. };
  73.  
  74. //---- Iterator0 ---------------------------------------------------------------
  75.  
  76. class Iterator0 : public Iterator {
  77. public:
  78.     Iterator0();
  79.     Object *operator()();
  80.     void Reset();
  81. };
  82.  
  83. #endif
  84.  
  85.